package com.hl.controller;

import com.hl.common.constant.Constants;
import com.hl.common.controller.BaseController;
import com.hl.common.domain.AjaxResult;
import com.hl.common.page.TableDataInfo;
import com.hl.domain.Region;
import com.hl.service.IRegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 区域管理Controller
 *
 * @author Jimbo
 * @date 2025-03-13
 */
@RestController
@RequestMapping("/region")
public class RegionController extends BaseController {
    @Autowired
    private IRegionService regionService;

    /**
     * 查询区域列表
     */
    @GetMapping("/list")
    public AjaxResult list(@RequestParam(value = Constants.PAGE_NUM, required = false, defaultValue = Constants.PAGE_NUM_DEFAULT) Integer pageNum,
                           @RequestParam(value = Constants.PAGE_SIZE, required = false, defaultValue = Constants.PAGE_SIZE_DEFAULT) Integer pageSize,
                           Region region) {
        Map<String, Object> map = regionService.selectRegionList(pageNum, pageSize, region);

        return success(map);
    }

    /**
     * 获取区域详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(regionService.selectRegionById(id));
    }

    /**
     * 新增区域
     */
    @PostMapping
    public AjaxResult add(@RequestBody Region region) {
        return toAjax(regionService.insertRegion(region));
    }

    /**
     * 修改区域
     */
    @PutMapping
    public AjaxResult edit(@RequestBody Region region) {
        return toAjax(regionService.updateRegion(region));
    }

    /**
     * 删除区域
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(regionService.deleteRegionByIds(ids));
    }
}
